import { gethouselistAPI , delhouseAPI} from "../../../api/houseapi"
Page({
  data: {
    dialogVisible: false,
    list:[],
    isloading:true,
  },
  onLoad() {
    // const res = getCurrentPages()
    // console.log(res);
    
  },

  onShow() {
    this.gethouselist()
  },

  async gethouselist() {
    const res = await gethouselistAPI()
    console.log(res);
    this.setData({
      list:res.data,
      isloading : false,
    })
  },

  async swipeClose(ev) {
    const { position, instance } = ev.detail

    if (position === 'right') {
      // 显示 Dialog 对话框
      // this.setData({
      //   dialogVisible: true,
      // })
      const res =  await wx.showModal({
        title:'温馨提示',
        content:'您确定要删除吗？',
        confirmColor:'#5591af',
      })
      // swiper-cell 滑块关闭
      instance.close()
      console.log(res.confirm);
      if (res.confirm) {
        await delhouseAPI(ev.mark.id)
        this.setData({
          list:this.data.list.filter(item => item.id !== ev.mark.id)
        })
      }
    }
  },

  goDetail(e) {
    console.log(e.mark.id);
    wx.navigateTo({
      url: `/house_pkg/pages/detail/index?id=${e.mark.id}`,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
